<template>
    <div class="app-container">
        <el-row :gutter="20" class="div-height-left">
            <el-col v-if="userInfo.userId === '1'" :span="4" class="div-height-left">
                <sys-org-tree @treeClick="treeClick" />
            </el-col>
            <el-col :span="userInfo.userId === '1' ? 20 : 24" :xs="24">
                <div class="search-container">
                    <div class="search-container">
                        <el-form v-show="showSearch" ref="queryParamsRef" :inline="true" :model="queryParams"
                            label-width="100px">
                            <el-form-item label="创建时间">
                                <el-date-picker v-model="dateRange" :unlink-panels="true" end-placeholder="结束日期"
                                    range-separator="截止" start-placeholder="开始日期" type="datetimerange"
                                    value-format="YYYY-MM-DD HH:mm:ss"></el-date-picker>
                            </el-form-item>
                            <el-form-item label="操作类型" prop="operationType">
                                <el-select class="width-120" v-model="queryParams.operationType" clearable
                                    placeholder="请选择操作类型">
                                    <el-option v-for="dict in dictDataMap['price_operation_type']" :key="dict.dictValue"
                                        :label="dict.dictLabel" :value="dict.dictValue" />
                                </el-select>
                            </el-form-item>
                            <el-form-item label="项目分类" prop="itemClass">
                                <el-select class="width-120" v-model="queryParams.itemClass" clearable filterable
                                    placeholder="请选择项目分类" @change="getList">
                                    <el-option v-for="dict in dictDataMap['bill_item_class_dict']" :key="dict.dictValue"
                                        :label="dict.dictLabel" :value="dict.dictValue" />
                                </el-select>
                            </el-form-item>
                            <el-form-item label="项目代码" prop="itemCode">
                                <el-input v-model="queryParams.itemCode" clearable placeholder="请输入项目代码"
                                    @keyup.enter.native="handleQuery" />
                            </el-form-item>
                            <el-form-item label="项目名称" prop="itemName">
                                <el-input v-model="queryParams.itemName" clearable placeholder="请输入项目名称"
                                    @keyup.enter.native="handleQuery" />
                            </el-form-item>
                            <el-form-item label="门诊费用分类" prop="classOnRcpt">
                                <el-select class="width-120" v-model="queryParams.classOnRcpt" clearable filterable
                                    placeholder="请选择门诊费用分类" @change="getList">
                                    <el-option v-for="dict in dictDataMap['outp_rcpt_fee_dict']" :key="dict.dictValue"
                                        :label="dict.dictLabel" :value="dict.dictValue" />
                                </el-select>
                            </el-form-item>
                            <el-form-item label="住院费用分类" prop="classOnInp">
                                <el-select class="width-120" v-model="queryParams.classOnInp" clearable filterable
                                    placeholder="请选择住院费用分类" @change="getList">
                                    <el-option v-for="dict in dictDataMap['inp_rcpt_fee_dict']" :key="dict.dictValue"
                                        :label="dict.dictLabel" :value="dict.dictValue" />
                                </el-select>
                            </el-form-item>
                            <el-form-item label="核算项目分类" prop="classOnReckoning">
                                <el-select class="width-120" v-model="queryParams.classOnReckoning" clearable filterable
                                    placeholder="请选择核算项目分类" @change="getList">
                                    <el-option v-for="dict in dictDataMap['reck_item_class_dict']" :key="dict.dictValue"
                                        :label="dict.dictLabel" :value="dict.dictValue" />
                                </el-select>
                            </el-form-item>
                            <el-form-item label="会计科目" prop="subjCode">
                                <el-select class="width-120" v-model="queryParams.subjCode" clearable filterable
                                    placeholder="请选择会计科目" @change="getList">
                                    <el-option v-for="dict in dictDataMap['tally_subject_dict']" :key="dict.dictValue"
                                        :label="dict.dictLabel" :value="dict.dictValue" />
                                </el-select>
                            </el-form-item>
                            <el-form-item filterable label="病案首页分类" prop="classOnMr">
                                <el-select class="width-120" v-model="queryParams.classOnMr" clearable
                                    placeholder="请选择病案首页分类" @change="getList">
                                    <el-option v-for="dict in dictDataMap['mr_fee_class_dict']" :key="dict.dictValue"
                                        :label="dict.dictLabel" :value="dict.dictValue" />
                                </el-select>
                            </el-form-item>
                            <div style="float: right" class="mr20">
                                <query-form-button @handleQuery="handleQuery" @resetQuery="resetQuery" />
                            </div>
                        </el-form>
                    </div>
                </div>
                <el-row :gutter="10" class="mb8">
                    <el-col :span="1.5">
                        <el-button v-hasPerm="['base:priceList:export']" :disabled="!queryParams.orgId" plain
                            type="warning" @click="handleExport"><template #icon><i-ep-download /></template>导出
                        </el-button>
                    </el-col>
                </el-row>

                <el-table v-adaptive :data="priceListList" :border="true" highlight-current-row stripe
                    :header-cell-style="$headerCellStyle">
                    <el-table-column :align="'left'" label="项目分类" prop="itemClass" width="100px">
                        <template #default="scope">
                            <dict-data-tag :options="dictDataMap['bill_item_class_dict']"
                                :value="scope.row.itemClass" />
                        </template>
                    </el-table-column>
                    <el-table-column :show-overflow-tooltip="true" :align="'left'" label="项目代码" min-width="100px"
                        prop="itemCode" />
                    <el-table-column :show-overflow-tooltip="true" :align="'left'" label="项目名称" fixed="left"
                        min-width="180px" prop="itemName" />
                    <el-table-column :show-overflow-tooltip="true" :align="'left'" label="项目规格" prop="itemSpec" />
                    <el-table-column :show-overflow-tooltip="true" :align="'left'" label="单位" prop="units" width="80px">
                        <template #default="scope">
                            <dict-data-tag :options="dictDataMap['spec_unit']" :value="scope.row.units" />
                        </template>
                    </el-table-column>
                    <el-table-column :show-overflow-tooltip="true" :align="'left'" label="价格(元)" prop="price" />
                    <el-table-column :show-overflow-tooltip="true" :align="'center'" label="是否最新价格" min-width="100px"
                        prop="isNew">
                        <template #default="scope">
                            <dict-data-tag :options="dictDataMap['is_new']" :value="scope.row.isNew" />
                        </template>
                    </el-table-column>
                    <el-table-column :show-overflow-tooltip="true" :align="'center'" label="门诊费用分类" min-width="100px"
                        prop="classOnRcpt">
                        <template #default="scope">
                            <dict-data-tag :options="dictDataMap['outp_rcpt_fee_dict']"
                                :value="scope.row.classOnRcpt" />
                        </template>
                    </el-table-column>
                    <el-table-column :show-overflow-tooltip="true" :align="'center'" label="住院费用分类" min-width="100px"
                        prop="classOnInp">
                        <template #default="scope">
                            <dict-data-tag :options="dictDataMap['inp_rcpt_fee_dict']" :value="scope.row.classOnInp" />
                        </template>
                    </el-table-column>
                    <el-table-column :show-overflow-tooltip="true" :align="'center'" label="核算项目分类" min-width="100px"
                        prop="classOnReckoning">
                        <template #default="scope">
                            <dict-data-tag :options="dictDataMap['reck_item_class_dict']"
                                :value="scope.row.classOnReckoning" />
                        </template>
                    </el-table-column>
                    <el-table-column :show-overflow-tooltip="true" :align="'center'" label="会计科目" min-width="100px"
                        prop="subjCode">
                        <template #default="scope">
                            <dict-data-tag :options="dictDataMap['tally_subject_dict']" :value="scope.row.subjCode" />
                        </template>
                    </el-table-column>
                    <el-table-column :show-overflow-tooltip="true" :align="'center'" label="病案首页分类" min-width="100px"
                        prop="classOnMr">
                        <template #default="scope">
                            <dict-data-tag :options="dictDataMap['mr_fee_class_dict']" :value="scope.row.classOnMr" />
                        </template>
                    </el-table-column>
                    <el-table-column :align="'center'" label="开始时间" prop="startDate" width="160">
                        <template #default="scope">
                            <span>{{ $parseTime(scope.row.startDate, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column :align="'center'" label="停止时间" prop="stopDate" width="160">
                        <template #default="scope">
                            <span>{{ $parseTime(scope.row.stopDate, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column :align="'center'" label="操作类型" prop="operationType">
                        <template #default="scope">
                            <dict-data-tag :options="dictDataMap['price_operation_type']"
                                :value="scope.row.operationType" />
                        </template>
                    </el-table-column>
                    <el-table-column :align="'center'" label="操作时间" prop="createTime" width="180">
                        <template #default="scope">
                            <span>{{ $parseTime(scope.row.createTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column :show-overflow-tooltip="true" :align="'left'" label="操作人" prop="createBy" />

                </el-table>

                <pagination v-show="total > 0" v-model:limit="queryParams.pageSize" v-model:page="queryParams.pageNum"
                    :total="total" @pagination="getList" />
            </el-col>
        </el-row>
    </div>
</template>

<script lang="ts" setup>
import {selectPagePriceListlog} from "@/api/base/priceListlog";
import {useDictStoreHook} from "@/store/modules/dict";
import {useUserStoreHook} from "@/store/modules/user";

const { proxy } = getCurrentInstance() as any
const dictStore = useDictStoreHook()
const useUserStore = useUserStoreHook();
// 登录用户信息
const userInfo = <UserInfoBusi>useUserStore.user.userInfo
const dictDataMap = ref(dictStore.isTypeGetData('tally_subject_dict', 'bill_item_class_dict', 'outp_rcpt_fee_dict', 'inp_rcpt_fee_dict',
    'reck_item_class_dict', 'mr_fee_class_dict', 'spec_unit', 'is_medical_insurance', 'price_operation_type', 'is_new'))

// 按钮loading
const buttonLoading = ref(false)
// 选中数组
const ids = ref([])
// 非单个禁用
const single = ref(true)
// 非多个禁用
const multiple = ref(true)
// 显示搜索条件
const showSearch = ref(true)
// 总条数
const total = ref(0)
// 价表表格数据
const priceListList = ref([])
// 弹出层标题
const title = ref("")
// 是否显示弹出层
const open = ref(false)
// 是否生成诊疗项目
const intoItemCheck = ref<boolean>(true)
// 不能编辑
const isNotEdit = ref(false)
// 诊疗项目下拉框
const billItemList = ref<any[]>([])
const dateRange = ref()
// 查询参数
const queryParamsRef = ref()
const queryParams = ref<PriceList>({
    pageNum: 1,
    pageSize: 10,
    itemClass: "",
    itemCode: "",
    itemName: "",
    itemSpec: "",
    medicalInsuranceType: "",
    units: "",
    classOnRcpt: "",
    classOnInp: "",
    classOnReckoning: "",
    subjCode: "",
    classOnMr: "",
    startDate: "",
    stopDate: "",
    inputCode: "",
    orgId: "",
    itemCodeYbCompare: "",
    zfOrYb: ""
})
if (userInfo.orgId) {
    queryParams.value.orgId = userInfo.orgId
    getList()
}

/** 左侧科室树节点点击事件 */
function treeClick(obj) {
    queryParams.value.orgId = obj.id
    getList()
}

/** 查询价表列表 */
function getList() {
    if (!queryParams.value.orgId) {
        return ElMessage.error("请先选择左侧所属机构后查询")
    }
    selectPagePriceListlog(proxy.$addDateRange(queryParams.value, dateRange.value)).then((response: any) => {
        priceListList.value = response.rows;
        total.value = response.total;
    });
}
/** 搜索按钮操作 */
function handleQuery() {
    queryParams.value.pageNum = 1;
    getList();
}
/** 重置按钮操作 */
function resetQuery() {
    queryParamsRef.value.resetFields()
    dateRange.value = [];
    handleQuery();
}
// 多选框选中数据
function handleSelectionChange(selection) {
    ids.value = selection.map((item: any) => item.priceId)
    single.value = selection.length !== 1
    multiple.value = !selection.length
}
/** 导出按钮操作 */
function handleExport() {
    // this.download('admin/priceList/export', {
    //     ...this.queryParams
    // }, `priceList_${new Date().getTime()}.xlsx`)
}
</script>
<script lang="ts">
export default {
    name: "PriceListlog"
};
</script>
